package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.AppFamilyMember;
import com.vf.admin.miaodong.entity.AppFamilyPrestige;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;


@Repository
public class AppFamilyPrestigeDao extends BaseDao<AppFamilyPrestige> {

    @Autowired
    private AppFamilyMemberDao appFamilyMemberDao;

    public void addPrestisge(Integer type, Integer num, Integer userId, String descMsg)
    {

    }

    public AppFamilyPrestige getDayPrestigenum(Integer userId)
    {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder stringBuilder2 = new StringBuilder("select *,sum(ifnull(prestigenum,0)) as dayPrestigenum from app_family_prestige where to_days(createtime) = to_days(now())");
        stringBuilder2.append(" and userId=?");
//        stringBuilder2.append(" GROUP BY userId");
        paramList.add(userId);
        String sql = stringBuilder2.toString();

        return this.queryObj(sql,paramList,AppFamilyPrestige.class);
    }


    public List<AppFamilyPrestige> getDayList(Integer userId)
    {
        AppFamilyMember family = appFamilyMemberDao.getFamily(userId);
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder stringBuilder2 = new StringBuilder("select *,sum(prestigenum) as total from app_family_prestige where to_days(createtime) = to_days(now())");
        if(family!=null){
            stringBuilder2.append(" and fid!=?");
            paramList.add(family.getFid());
        }
        stringBuilder2.append(" GROUP BY fid ORDER BY total desc limit 100");
        String sql = stringBuilder2.toString();

        return this.queryList(sql,paramList,AppFamilyPrestige.class);
    }

    public List<AppFamilyPrestige> getDayList()
    {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder stringBuilder2 = new StringBuilder("select *,sum(prestigenum) as total from app_family_prestige where to_days(createtime) = to_days(now())");
        stringBuilder2.append(" GROUP BY fid ORDER BY total desc limit 100");
        String sql = stringBuilder2.toString();

        return this.queryList(sql,paramList,AppFamilyPrestige.class);
    }

    public List<AppFamilyPrestige> getWeekList(Integer userId)
    {
        ArrayList<Object> paramList = new ArrayList<Object>();
        AppFamilyMember family = appFamilyMemberDao.getFamily(userId);
        StringBuilder stringBuilder2 = new StringBuilder("select *,sum(prestigenum) as total from app_family_prestige where YEARWEEK( date_format(  createtime,'%Y-%m-%d' ) ) = YEARWEEK( now() )");
        if(family!=null){
            stringBuilder2.append(" and fid!=?");
            paramList.add(family.getFid());
        }
        stringBuilder2.append(" GROUP BY fid ORDER BY total desc limit 100");
        String sql = stringBuilder2.toString();

        return this.queryList(sql,paramList,AppFamilyPrestige.class);
    }

    public List<AppFamilyPrestige> getWeekList()
    {
        StringBuilder stringBuilder2 = new StringBuilder("select *,sum(prestigenum) as total from app_family_prestige where YEARWEEK( date_format(  createtime,'%Y-%m-%d' ) ) = YEARWEEK( now() ) GROUP BY fid ORDER BY total desc limit 100");
        String sql = stringBuilder2.toString();
        ArrayList<Object> paramList = new ArrayList<Object>();
        return this.queryList(sql,paramList,AppFamilyPrestige.class);
    }


    public List<AppFamilyPrestige> getMonthList()
    {
        String sql = "select *,sum(prestigenum) as totalPrestige from app_family_prestige where DATE_FORMAT( createtime, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) GROUP BY fid ORDER BY totalPrestige desc limit 100";
        ArrayList<Object> paramList = new ArrayList<Object>();
        return this.queryList(sql,paramList,AppFamilyPrestige.class);
    }





}
